<?php 
	require_once '../util/dbconnection.php';
	require_once '../util/public.php';
	
	$action = $_GET['action'];
	if( isset($action) && $action=="login" ){
		$login_error = false;
		$login_msg = "";
		$username = $_POST['username'];
		$pwd = $_POST['pwd'];
		if(  $username == '' ){
			$login_error = true;
			$login_msg = "请填写用户名";
		}
		if( $pwd == '' ){
			$login_error = true;
			$login_msg = "请输入密码";
		}
		if( $login_error == false ){
			$user = retrive_user_info( $username );
			// 登录成功
			if( md5($pwd) == $user['password'] ){
				$login_error = false;
				// 写session
				session_start();
				$_SESSION['login_user'] = $user['username'];
				$_SESSION['login_id'] = $user['id'];
				// 进入管理页面
				site_redirct("post-admin.php");
			}else{
				$login_error = true;
				$login_msg = '密码错误&nbsp; <a href="#"> 忘记密码? </a>';
			}
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理员登陆</title>

<style type="text/css">
html{
	background: #F9F9F9;
}

body{
	margin: 0;
}

#backtitle{
	margin-left: 40;
	padding-top: 5px;
	padding-bottom: 5px;
	width: 100%;
	background-color: #505050;
	font-size: 12px;
	display: block;
}

#backtitle a{
	padding-left: 40px;
	color: white;
	text-decoration: none;
}

#error_msg{
	margin: 0 auto 10px 8px;
	padding-left: 10px;
	border: 1px solid red;
	border-radius: 3px;
	-moz-border-radius: 3px;
	-khtml-border-radius: 3px;
	-webkit-border-radius: 3px;
	background-color: #FFEBE8;
	font-size: 13px;
}

#container{
	width: 320px;
	margin-top: 7em;
	margin-right: auto;
	margin-bottom: 7em;
	margin-left: auto;
	display: block;
}

#container form{
	margin-left: 8px;
	padding: 10px 16px 10px 16px;
	background: white;
	border-radius: 5px;
	-moz-border-radius: 5px;
	-khtml-border-radius: 5px;
	-webkit-border-radius: 5px;
	border: 1px solid #E5E5E5;
	-moz-box-shadow: rgba(200, 200, 200, 1) 0 4px 18px;
	-webkit-box-shadow: rgba(200, 200, 200, 1) 0 4px 18px;
	-khtml-box-shadow: rgba(200, 200, 200, 1) 0 4px 18px;
	box-shadow: rgba(200, 200, 200, 1) 0 4px 18px;
	display: block;
}

label{
	font-size: 13px;
}

#username, #pwd{
	font-size: 24px;
	width: 97%;
	padding: 3px;
	margin-top: 2px;
	margin-right: 6px;
	margin-bottom: 10px;
	border: 1px solid #E5E5E5;
	background: #FBFBFB;
}

#submitp{
	margin-bottom: 0px;
	display: block;
}

h1 a{
	background: url(../images/login.png) no-repeat top center;
	width: 326px;
	height: 67px;
	overflow: hidden;
	margin: 0px;
	overflow: hidden;
	text-indent: -9999px;
	display: block;
}
</style>
</head>

<body>
<div id="backtitle">
	<a href=".." >←返回站点</a>
</div>
<div id="container">
	<h1><img src="../images/login.png"></img></h1>
	<?php 
	if( $login_error == true ){
		echo '<div id="error_msg">';
		echo '<p>错误：'.$login_msg.'</p>';
		echo '</div>';
	}
	?>
	<form action="login.php?action=login" method="post" id="loginform" name="loginform">
	<p><label>用户名</label><br/><input type="text" id="username" name="username" size="20" class="input"></input></p>
	<p><label>密码</label><br/><input type="password" id="pwd" name="pwd" size="20" class="input"></input></p>
	<p id="submit"><input type="submit" id="submit" name="submit" value="登录"></input></p>
	</form>
	
</div>

</body>
</html>
